<template>
  <div class="login-container" :style="'background-image:url(' + require('@/assets/ik/images/loginbg.png') + ')'">
    <div class="login-top">
      <div class="login-top-container">
        <img src="@/assets/ik/images/logo.png" class="logo">
        <div class="menu">
          <p class="menu-item menu-help">
            <a href="/html/login.html">帮助</a>
          </p>
          <p class="menu-item menu-phone">电话：0533-2389299</p>
        </div>
      </div>
    </div>
    <div class="login-body flex align-center">
      <img class="login-img" src="@/assets/ik/images/login.png" alt="">
      <div class="login-body-container">
        <el-form
          ref="formData"
          class="login-form"
          :model="formData"
          :rules="rules"
          auto-complete="on"
          label-position="left"
        >
          <h2> 导萃门诊管理系统 </h2>
          <el-form-item prop="username">
            <el-input
              v-model="formData.userCode"
              class="w-full"
              type="text"
              prefix-icon="user"
              @keyup.enter.native="login"
            >
              <template #prefix>
                <svg-icon class="font-black ml-5" icon-class="user" />
              </template>
            </el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input
              v-model="formData.passWord"
              :type="passwordType"
              @keyup.enter.native="login"
            >
              <template #prefix>
                <span class="flex flex-row align-center h-full">
                  <svg-icon class="font-black ml-5" icon-class="password" />
                </span>
              </template>
              <template #append>
                <span class="show-pwd flex flex-row align-center" @click="showPwd">
                  <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
                </span>
              </template>
            </el-input>
          </el-form-item>
          <el-button
            :loading="loading"
            type="primary"
            style="width:100%;margin-bottom:10px;"
            @click.native.prevent="login"
          >登录
          </el-button>
          </h2></el-form>
      </div>
    </div>
    <div class="login-bottom">
      <div class="login-bottom-container">
        <p class="copyright">网站备案：
          <a href="https://beian.miit.gov.cn">沪ICP备20009190号-2</a>
        </p>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Login',
  data() {
    return {
      timer: 0,
      formData: {
        userCode: '',
        passWord: ''
      },
      // 验证规则
      rules: {
        userCode: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
          { min: 6, max: 15, message: '长度在6到15个字符', trigger: 'blur' }
        ],
        passWord: [
          { required: true, message: '请输入用户密码', trigger: 'blur' },
          { min: 6, max: 30, message: '长度在6到30个字符', trigger: 'blur' }
        ]
      },
      // 登录标识
      loading: false,
      // 密码显示方式
      passwordType: 'password',
      title: this.$store.getters['setting/getTitle']
    }
  },
  created() {
  },
  mounted() {
  },
  methods: {
    // 切换密码显示
    showPwd() {
      if (this.passwordType === 'password') {
        this.passwordType = 'text'
      } else {
        this.passwordType = 'password'
      }
    },
    // 登录
    login() {
      this.loading = true
      const $this = this
      // 测试代码，使用默认账号登录
      if (this.formData.userCode === "admin" && this.formData.passWord === "DaoCui@2000") {
        // 写入用户信息
        this.$store.dispatch('user/login', {
          'token': 'testToken',
          'userCode': this.formData.userCode,
          'userName': this.formData.userCode,
          'userRole': 'ADMIN',
          'roleCode': 'manager',
          'roleName': '管理组',
          'securityLevel': '',
          'fieldSecurityLevel': ''
        })
        $this.$router.push({ path: $this.redirect || '/base/home' })
        $this.loading = false
      } else {
        $this.$message({ type: 'error', message: '用户名、密码错误' })
        $this.loading = false
      }

      /*
      const loginData = JSON.parse(JSON.stringify(this.loginForm))
      this.$store.dispatch('user/testLogin', loginData).then(function() {
        $this.$router.push({ path: $this.redirect || '/' })
        $this.loading = false
      }).catch(() => {
        this.loading = false
      })
      */
    }
  }
}
</script>

<style lang="scss" scoped>
$bg: #000000;
$dark_gray: #889aa4;
$light_gray: #eeeeee;
.login-container {
  width: 100%;
  min-height: 100%;
  background-color: $bg;
  overflow: hidden;
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-position: center;
  background-size: 100% 100%;
  position: relative;
}

.login-top {
  width: 100%;
  min-width: 1200px;
  height: 80px;
  padding: 13px 0;
  background: #005ed9;
  -webkit-backdrop-filter: blur(10px) brightness(110%);
  backdrop-filter: blur(10px) brightness(110%);
  position: absolute;
  z-index: 9;

  .login-top-container {
    width: 1200px;
    margin: 0 auto;
    height: 38px;
    position: relative;

    .logo {
      width: 414px;
      height: 52px;
      float: left;
    }

    .menu {
      position: absolute;
      right: 0;

      .menu-item {
        padding: 0 25px;
        float: left;
        font-size: 16px;
        color: #fff;
      }
    }
  }
}

.login-body {
  margin-top: 200px;
  width: 100%;
  min-width: 1200px;
  display: flex;

  .login-img {
    margin-left: 200px;
    width: 800px;
    height: 400px;
    overflow: hidden;
    background: rgba(255, 255, 255);
  }

  .login-body-container {
    width: 500px;
    margin: 0 auto;
    height: 100%;
    position: relative;

    ::v-deep.login-form {
      width: 400px;
      height: 400px;
      overflow: hidden;
      padding: 40px 60px;
      background: rgba(255, 255, 255);
      border: 2px solid #005ed9;

      .title {
        margin: 20px auto;
        padding: auto;
        height: 38px;
        text-align: center;
        font-size: 24px;
        color: #005ed9;
      }

      .el-form-item {
        .el-form-item__content {
          width: 100%;
          background-color: rgba(170, 170, 170, 0.6)
        }

        .svg-container {
          padding: 6px 5px 6px 15px;
          vertical-align: middle;
          width: 30px;
          font-size: 24px;
          color: #FFF;
          display: inline-block;
        }

        .svg-icon {
          color: #FFF;
        }

        .el-input {
          display: inline-block;
          height: 47px;
          width: 85%;

          input {
            border: 0px;
            color: #FFF;
            border-radius: 0px;
            padding: 12px 5px 12px 15px;
            height: 47px;
            background: transparent;
            -webkit-appearance: none;

            ::placeholder {
              color: #eeeeee;
            }
          }
        }
      }

      .register {
        margin: 0px;
        font-size: 14px;
        color: #FFF;
      }
    }

    .tips {
      font-size: 14px;
      color: #fff;
      margin-bottom: 10px;

      span {
        &:first-of-type {
          margin-right: 16px;
        }
      }
    }

    .title-container {
      position: relative;

      .title {
        font-size: 26px;
        color: $light_gray;
        margin: 0px auto 40px auto;
        text-align: center;
        font-weight: bold;
      }
    }

    .show-pwd {
      position: absolute;
      right: 10px;
      top: 7px;
      font-size: 16px;
      color: $dark_gray;
      cursor: pointer;
      user-select: none;
    }
  }
}

.login-bottom {
  width: 100%;
  min-width: 1200px;
  height: 80px;
  padding: 21px 0;
  background: #005ed9;
  -webkit-backdrop-filter: blur(10px) brightness(110%);
  backdrop-filter: blur(10px) brightness(110%);
  position: absolute;
  bottom: 0;

  .login-bottom-container {
    width: 1200px;
    margin: 0 auto;
    height: 38px;
    position: relative;

    .copyright {
      font-size: 12px;
      color: #fff;
    }
  }
}
</style>
